import React, { useEffect, useState } from 'react'
import styles from './current.module.scss'

import { NavLink, useNavigate } from 'react-router-dom'
import { Empty, Button,NavBar,Toast  } from 'react-vant';
import http from '../../../http'
import dayjs from 'dayjs';
import calendar from 'dayjs/plugin/calendar'
dayjs.extend(calendar)
export default function Current() {
  //当前问诊数据
  const [NowConsultation,setConsultation]=useState<any>({})
  const naviagte=useNavigate()
  useEffect(()=>{
   http.get('/health/user/inquiry/verify/v1/findCurrentInquiryRecord').then((res:any)=>{
    console.log(res);
    if(res.result){
      setConsultation(res.result)
    }else{
     setConsultation({}) 
    }
    
   })
  },[])
  // console.log(NowConsultation);
  //结束问诊
  const EndConsultation=()=>{
    const recordId=NowConsultation.recordId
    http.put(`health/user/inquiry/verify/v1/endInquiry?recordId=${recordId}`)
    naviagte('/my')
  }
  return (
    
    <div className={styles.box}>
       <NavBar
      title="当前问诊"
      onClickLeft={() =>naviagte('/my')}
     
    />
    {/* 判断当前问诊是否有数据 */}
      {Object.keys(NowConsultation).length === 0 ? (
           <Empty description="暂无问诊">
      <Button style={{ width: 160 }} round type="primary" onClick={()=>naviagte('/my')}>
        点击返回
      </Button>
    </Empty>
      ) : (
        <div className={styles.NowConsultationBox}>
          <div className={styles.doctorImg}>
            <img src={NowConsultation.imagePic} alt="" />
          </div>
          <div className={styles.doctorMessage}>
            <div className={styles.doctor}>
                 <div style={{fontWeight:'bold'}}>{NowConsultation.doctorName}</div>
            <div>{NowConsultation.jobTitle}</div>
            <div>{NowConsultation.department}</div>
            <div>问诊时间:{dayjs(NowConsultation.inquiryTime).calendar(null,{
                    sameDay: '今天 HH:mm', // The same day ( Today at 2:30 AM )
                    nextDay: '[Tomorrow]', // The next day ( Tomorrow at 2:30 AM )
                    nextWeek: 'dddd', // The next week ( Sunday at 2:30 AM )
                    lastDay: '[昨天]', // The day before ( Yesterday at 2:30 AM )
                    lastWeek: '[上周] dddd', // Last week ( Last Monday at 2:30 AM )
                    sameElse: 'YYYY/DD/MM HH:mm' // Everything else ( 7/10/2011 )
                   })}</div>
               
            </div>
          </div>
          <div className={styles.Button}>
             <Button color='#ccc' className={styles.butn} onClick={()=>naviagte( `/chatRroom?doctorId=${NowConsultation.doctorId}&recordId=${NowConsultation.recordId}&doctorName=${NowConsultation.doctorName}&imagePic=${NowConsultation.imagePic}`)}>继续问诊</Button>
           <Button type='primary' className={styles.butn} onClick={()=>EndConsultation()}>结束问诊</Button>
          </div>
        </div>
      )}
    </div>
  )
}
